//
//  WBPresentConreoller.swift
//  WeiBoDemo
//
//  Created by mac on 2017/11/20.
//  Copyright © 2017年 mac. All rights reserved.
//

import UIKit

class WBPresentConreoller: UIPresentationController {

    //MARK:-对外提供属性
    var presentedFrame : CGRect = CGRect.zero
    
    //MARK: -懒加载属性
    private lazy var coverView : UIView = UIView()
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        //1.设置弹出View的尺寸
        presentedView?.frame = presentedFrame//CGRect.init(x: 100, y: 55, width: 180, height: 255)
        //2.添加蒙版
        setupCoverView()
    }
}

//MARK: -设置UI界面相关
extension WBPresentConreoller{
    private func setupCoverView(){
        //1。添加蒙版
        containerView?.insertSubview(coverView, at: 0)
        //2.设置蒙版的属性
        coverView.backgroundColor = UIColor.init(white: 0.8, alpha: 0.2)
        coverView.frame = containerView!.bounds
//        coverView.frame = containerView?.bounds ?? CGRectZero
        //3.添加手势
        let tapGes = UITapGestureRecognizer.init(target: self, action: #selector(WBPresentConreoller.coverViewClick))
        coverView.addGestureRecognizer(tapGes)
    }
}


//MARK: -事件监听
extension WBPresentConreoller{
    @objc private func coverViewClick(){
        print("coverViewClick")
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
